const mysql = require('mysql2');

// 创建数据库连接配置对象
const connectionConfig = {
    host: 'localhost',
    user: 'root',
    password: 'root',
    database: 'demo1'
};

// 创建连接池
const pool = mysql.createPool(connectionConfig);

// 测试连接
pool.getConnection((err, connection) => {
    if (err) {
        console.error('Database connection failed! Error:', err);
        return;
    }
    console.log('Connected to the database!');
    // 释放连接
    connection.release();
});

// 关闭连接池
pool.end(() => {
    console.log('Database connection closed.');
});